using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SettingsUIControl : MonoBehaviour
{
    public GameObject soundOpen;
    public GameObject musicOpen;
    AudioSource[] music;
    // Start is called before the first frame update
    void Start()
    {
        music = GameObject.Find("Game").GetComponents<AudioSource>();
        soundOpen.transform.Find("soundClose").gameObject.SetActive(false);
        musicOpen.transform.Find("musicClose").gameObject.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void closeThisPage()
    {
        // gameObject.SetActive(false);
        Destroy(gameObject);
    }
    public void SetSound()
    {
        GameManager.Instance.isSound = !GameManager.Instance.isSound;
        closeGameSound();
        soundOpen.transform.Find("soundClose").gameObject.SetActive(!GameManager.Instance.isSound);
    }
    public void SetMusic()
    {
        GameManager.Instance.isMusic = !GameManager.Instance.isMusic;
        closeGameMusic();
        musicOpen.transform.Find("musicClose").gameObject.SetActive(!GameManager.Instance.isMusic);
    }

    //关闭所有音效
    void closeGameSound()
    {
        if (GameManager.Instance.isSound)
            music[0].Play();
        else
            music[0].Stop();
    }
    //关闭bmg音乐
    void closeGameMusic()
    {
        if (GameManager.Instance.isMusic)
            music[1].Play();
        else
            music[1].Stop();
    }
    public void BackHome()
    {
        music[0].Stop();
        music[1].Stop();
        SceneManager.LoadScene("mainScene");
    }
}
